package com.enzo.prms.common.util;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Class name:	SpringContextHolder.java
 * @author: yiqun
 * @modified: August 03,2012
 */
public class SpringContextHolder {
    private static String APP_CONTEXT_FILE_NAME = "applicationContext-common.xml";
    private static ApplicationContext appContext;

    public static ApplicationContext getAppContext() {
        if (appContext == null) {
            reloadContext();
        }
        return appContext;
    }

    public static void setAppContext(ApplicationContext appContext) {
        SpringContextHolder.appContext = appContext;
    }

    public static Object getBean(String beanName) {
        return appContext.getBean(beanName);
    }

    public static void reloadContext() {
        appContext = new ClassPathXmlApplicationContext(APP_CONTEXT_FILE_NAME);
    }
}
